﻿Imports DAO

Public Class CidadeConsulta
    Inherits System.Web.UI.UserControl

    Public Event Editar(ByVal cidadeId As Integer)

    Public Event Excluir(ByVal cidadeId As Integer)

    Public Event Search(ByVal condicoes As List(Of Condicao))


    Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load

    End Sub

    Public Sub carregarCidades(ByVal list As List(Of Cidade))
        dtlConsulta.DataSource = list
        dtlConsulta.DataBind()
    End Sub

    Public Sub LimparConsulta()
        Me.CondicaoHeaderId.LimparText()
        Me.CondicaoHeaderNm.LimparText()
    End Sub

    Protected Sub dtlConsulta_ItemCommand(ByVal source As Object, ByVal e As DataListCommandEventArgs) Handles dtlConsulta.ItemCommand
        Dim lblID As Label = e.Item.FindControl("lblID")
        If e.CommandName.Equals("Editar") Then
            RaiseEvent Editar(CInt(lblID.Text))
        Else
            RaiseEvent Excluir(CInt(lblID.Text))
        End If
    End Sub

    Protected Sub SearchCondicao() Handles CondicaoHeaderId.TextChanged, CondicaoHeaderNm.TextChanged
        Dim condicoes As List(Of Condicao) = New List(Of Condicao)
        If Me.CondicaoHeaderId.TemValor Then
            condicoes.Add(CondicaoHeaderId.condicao)
        End If
        If Me.CondicaoHeaderNm.TemValor Then
            condicoes.Add(CondicaoHeaderNm.condicao)
        End If
        RaiseEvent Search(condicoes)
    End Sub

End Class